VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsCategorias"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Dim vSQL As String

Public pNumError As Long
Public pDesError As String
Public pCanReg As Long
Public pRS As ADODB.Recordset
Public pIdDevuelto As Long

Private vIdCategoria As Long

Public Property Let IdCategoria(ByVal VData As Long)
    vIdCategoria = VData
End Property
Public Property Get IdCategoria() As Long
    IdCategoria = vIdCategoria
End Property

Private Sub AsignarValores(Optional ByVal rs As ADODB.Recordset, Optional pNoAsigRs As Boolean)
    If Not pNoAsigRs Then
        Set Me.pRS = rs
    End If
    Me.pCanReg = objCnxAeros.pCanReg
    Me.pDesError = objCnxAeros.pDesError
    Me.pIdDevuelto = objCnxAeros.pUltIdenOtor
    Me.pNumError = objCnxAeros.pNumError
End Sub

Public Function sel_Categorias(Optional ByVal nombreCategoria)
Dim rs As New ADODB.Recordset
Dim strSQL As String

    If Not IsMissing(nombreCategoria) Then
        strSQL = "SELECT id_categoria,categoria From categorias WHERE fecha_baja is null AND categoria like '%" & nombreCategoria & "%' ORDER BY categoria"
    Else
        strSQL = "SELECT id_categoria,categoria From categorias WHERE fecha_baja is null ORDER BY categoria"
    End If
    
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    AsignarValores rs

End Function

Public Function ActualizarCategoria_by_ID(ByVal id_categoria As Long, categoria As String, _
                                    descripcion As String) As Boolean
Dim strSQL As String

strSQL = " UPDATE categorias SET categoria='" & categoria & _
                                        "',descripcion='" & descripcion & _
                                        "' WHERE categorias.id_categoria =" & id_categoria
    
                                        
    If objCnxAeros.EjecutarComando(strSQL) Then
        ActualizarCategoria_by_ID = True
    Else
        ActualizarCategoria_by_ID = False
    End If

End Function

Public Function BorrarCategoria_by_ID(ByVal ID As Long)
Dim strSQL As String

    strSQL = " UPDATE categorias SET fecha_baja ='" & Date & "'" & _
             " WHERE categorias.id_categoria =" & ID

    If objCnxAeros.EjecutarComando(strSQL) Then
        BorrarCategoria_by_ID = True
    Else
        BorrarCategoria_by_ID = False
    End If

End Function

Public Function grabarCategoria(ByVal categoria As String, ByVal descripcion As String)

Dim strSQL As String
    
    strSQL = " INSERT INTO categorias (categoria,descripcion) values ('" & categoria & "','" & descripcion & "')"
                                    
    If objCnxAeros.EjecutarComando(strSQL) Then
        grabarCategoria = True
    Else
        grabarCategoria = False
    End If

End Function

Public Function cargarCategoria_by_ID(ByVal ID As Long)
Dim rs As New ADODB.Recordset
Dim strSQL As String
   
   strSQL = " SELECT id_categoria, categoria,descripcion, " & _
            " fecha_baja FROM categorias WHERE id_categoria = " & ID
    
    Set rs = objCnxAeros.EjecutarConsulta(strSQL)
    
    AsignarValores rs

End Function






